<template>
  <div class="base-echart">
    <div ref="echartDivRef" :style="{ width: width, height: height }"></div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted, PropType, watchEffect } from 'vue'
import useEchart from '../hook/useEchart'
export default defineComponent({
  props: {
    options: {
      type: Object
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '360px'
    }
  },
  setup(props) {
    const echartDivRef = ref<HTMLElement>()
    onMounted(() => {
      const { setOptions } = useEchart(echartDivRef.value!)

      watchEffect(() => {
        setOptions(props.options!)
      })
    })
    return {
      echartDivRef
    }
  }
})
</script>

<style scoped></style>
